package project1;

import project1.service.ShopService;
import project1.service.ShopServiceImpl;
import project1.service.WalkService;
import project1.service.WalkServiceImpl;

import java.util.Scanner;

/**
 * 电商平台
 */
public class Main {
    public static final Scanner scanner = new Scanner(System.in);
    private static final String[] menus = new String[]{
            "查询所有商品",
            "根据商品编号查找图书",
            "购买书籍",
            "取消购买",
            "查询购买情况",
            "退出系统"
    };
    private static final WalkService walkService = new WalkServiceImpl();
    private static final ShopService shopService = new ShopServiceImpl();

    /**
     * 入口类
     */
    public static void main(String[] args) {
        while (true) {// 不断循环
            showMenu();// 展示菜单
            if (selectMenu(scanner.nextInt()))// 选择菜单
                return;
        }
    }

    /**
     * 展示菜单
     */
    private static void showMenu() {
        System.out.println("***********商品管理系统*************");
        for (int i = 0; i < menus.length; i++) {
            System.out.println(i + "." + menus[i]);
        }
        System.out.println("*********************************");
        System.out.println("请选择(1-6):");
    }

    /**
     * 选择菜单
     */
    private static boolean selectMenu(int index) {
        if (index < 0 || index >= menus.length) {
            System.out.println("请输入正确选项");
            return false;
        }
        // 根据输入显示
        System.out.printf("您选择了:%s业务\r\n", menus[index]);
        switch (index) {
            case 0:// 处理查询所有书籍的业务
                walkService.showBooks();
                break;
            case 1:// 处理按书籍编号查询
                walkService.showBook();
                break;
            case 2:// 购买书籍，将书籍加入到用户的购物车中
                shopService.addToCart();
                break;
            case 3:// 删除书籍，从购物车中删除书籍信息
                shopService.removeFromCart();
                break;
            case 4:// 显示某个用户购物车中所有的书籍
                shopService.showCart();
                break;
            case 5:// 退出当前应用程序
                return true;
        }
        return false;
    }
}